package com.solcoo.common.util;

public final class NumberUtil {

	public static int toInt(Object o) {
		return toInt(o, 0);
	}

	public static int toInt(Object o, int def) {
		if (o == null) {
			return def;
		}
		if (o instanceof Integer) {
			return (Integer) o;
		}
		if (o instanceof String && StringUtil.isNumeric(o.toString())) {
			return Integer.parseInt(o.toString());
		}
		return def;
	}

	public static int defaultIfValue(int src, int ifValue, int def) {
		return src == ifValue ? def : src;
	}
}
